package cn.wolfcode.wolf2w.web.controller;

import cn.wolfcode.wolf2w.annotation.RequireLogin;
import cn.wolfcode.wolf2w.annotation.UserParam;
import cn.wolfcode.wolf2w.domain.StrategyComment;
import cn.wolfcode.wolf2w.domain.UserInfo;
import cn.wolfcode.wolf2w.query.StrategyCommentQuery;
import cn.wolfcode.wolf2w.query.StrategyQuery;
import cn.wolfcode.wolf2w.query.TravelQuery;
import cn.wolfcode.wolf2w.redis.service.IUserInfoRedisService;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IStrategyCommentService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.IUserInfoService;
import cn.wolfcode.wolf2w.util.JsonResult;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("strategies")//旅游攻略控制器
public class StrategyController {

    @Autowired
    private IStrategyCommentService strategyCommentService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IUserInfoService  userInfoSerivce;
    //攻略明细分页
    @GetMapping("/query")
    public Object query(StrategyQuery qo){
        return JsonResult.success(strategyService.query(qo));
    }

    //查询某个发布的攻略
    //当用户点攻略集合中的某个攻略时,就展示某个攻略
    @GetMapping("/detail")
    public Object list(String id){
        return JsonResult.success( strategyService.getstrategy(id));
    }

    //评论列表  一刷新页面就访问这个接口
    @GetMapping("/comments")
    public Object getstrategy(StrategyCommentQuery qo){
        Page<StrategyComment> page = strategyCommentService.query(qo);
        return JsonResult.success(page);
    }
    //评论点赞操作
    @RequireLogin
    @PostMapping("/commentThumb")
    public Object thumbupnum(String cid,@UserParam UserInfo user){
         strategyCommentService.thumbupnum(cid,user.getId());
         //如果有异常就返回统一异常抛出的信息  联系管理员
        //没有异常就返回成功
        return JsonResult.success();
    }


    //攻略评论
    //评论添加操作
    //StrategyComment 用攻略评论对象用来接收攻略的id和攻略的标题
    //因为要给哪个攻略加评论,需要知道是哪个攻略的
    //@UserParam UserInfo info
    @RequireLogin //如果控制器的方法贴有这个标签, 表示该方法必须登录之后才可以访问//要放在下面的注解之前
    @PostMapping("/addComment")
    public Object addComment(StrategyComment strategyComment, HttpServletRequest request,@UserParam UserInfo info) {
//        String token = request.getHeader("token");
//        UserInfo user = userInfoSerivce.getUserByToken(token);
        strategyCommentService.addComment(strategyComment,info);
        return JsonResult.success();
        }







}
